package com.hnichr.ump.talent.library.controller;


import com.hnichr.ump.common.ecard.entity.EcardBusinessCard;
import com.hnichr.ump.common.ecard.entity.EcardCompany;
import com.hnichr.ump.common.talent.library.entity.PersonalInfo;
import com.hnichr.ump.common.talent.library.entity.Resume;
import com.hnichr.ump.common.talent.library.service.ResumeService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/talent/resume/v1/")
@Tag(name = "ResumeController", description = "人才库接口")
public class ResumeController {

    @Autowired
    private ResumeService resumeService;

    @GetMapping("list")
    @Operation(summary = "人才库列表", description = "获取人才库列表（无分页）", method = "GET")
    public Result<List<Resume>> list(@Parameter(description="查询参数") Criteria criteria){
        List<Resume> list = resumeService.list(Resume.class,criteria);
        return Result.OK(list);
    }

    @GetMapping("page")
    @Operation(summary = "人才库列表", description = "人才库列表（分页）", method = "GET")
    public Result<Page<Resume>> page(@Parameter(description="查询参数")  Criteria criteria, @Parameter(description="每页条数")Integer pageSize, @Parameter(description="页号")Integer pageNo){
        Pageable page = PageRequest.of(pageNo-1, pageSize);
        Page<Resume> list = resumeService.listPage(page, criteria);
        return Result.OK(list);
    }

    @GetMapping("list/{id}")
    @Operation(summary = "根据ID获取人才库", description = "根据ID获取人才库", method = "GET")
    public Result<Resume> getById(@Parameter(description="ID") @PathVariable(name = "id", required = true) String id) {
        Resume resume = resumeService.getById(id);
        if(resume.getPersonalInfo()==null){
            resume.setPersonalInfo(new PersonalInfo());
        }
        return Result.OK(resume);
    }
}
